import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [

  /* 大屏 */
  {
    path: '/bigscreen',
    component: () => import('@/views/BigScreen/index'),
    hidden: true,
    meta: { title: '大屏'},
  },


  /* 登录 */
  {
    path: '/login',
    component: () => import('@/views/Login/index'),
    hidden: true,
    meta: { title: '登录'}
  },

  /* 企业看板 */
  {
    path: '/company',
    redirect: '/company',
    component: Layout,
    children:[
      {
        path: 'company',
        component: () => import('@/views/Dashboard/index'),
        name: 'company',
      }
    ]
  },

  /* 单位设置 */
  {
    path: '/',
    component: Layout,
    redirect: '/UnitSetting/home',
    children:[
      {
        path: '/UnitSetting/home',
        component: () => import('@/views/UnitSetting/home/index'),
        name: 'UnitSettingHome',
      }
    ]
  },

  /* 平台信息 */
  {
    path: '/PlatformInfo',
    component: Layout,
    redirect: '/PlatformInfo/home',
    children:[
      {
        path: '/PlatformInfo/home',
        component: () => import('@/views/PlatformInfo/home/index'),
        name: 'PlatformInfoHome',
      }
    ]
  },

  /* 计量器具 */
  {
    path: '/MeasureManage',
    component: Layout,
    redirect: '/MeasureManage/home',
    children:[
      {
        path: '/MeasureManage/home',
        component: () => import('@/views/MeasureManage/home/index'),
        name: 'MeasureManageHome',
      }
    ]
  },

  /* 能源品种 */
  {
    path: '/EnergyVarieties',
    component: Layout,
    redirect: '/EnergyVarieties/home',
    children:[
      {
        path: '/EnergyVarieties/home',
        component: () => import('@/views/EnergyVarieties/home/index'),
        name: 'EnergyVarietiesHome',
      }
    ]
  },

  /* 工序管理 */
  {
    path: '/ProcedureManage',
    component: Layout,
    redirect: '/ProcedureManage/home',
    children:[
      {
        path: '/ProcedureManage/home',
        component: () => import('@/views/ProcedureManage/home/index'),
        name: 'ProcedureManageHome',
      }
    ]
  },

  /* 采集数据 */
  {
    path: '/CollectDatas',
    component: Layout,
    redirect: '/CollectDatas/home',
    children:[
      {
        path: '/CollectDatas/home',
        component: () => import('@/views/CollectDatas/home/index'),
        name: 'CollectDatasHome',
      }
    ]
  },

  /* 用户管理 */
  {
    path: '/UserManage',
    component: Layout,
    redirect: '/UserManage/home',
    children:[
      {
        path: '/UserManage/home',
        component: () => import('@/views/UserManage/home/index'),
        name: 'UserManageHome',
      }
    ]
  },

  /*404页面*/
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
